package com.yazi.mxz.common.db.dao.impl;


import java.util.HashMap;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.yazi.mxz.common.db.dao.ShoppingCartDao;
import com.yazi.mxz.common.entity.beans.Member;
import com.yazi.mxz.common.entity.beans.ShoppingCart;
import com.yazi.mxz.common.entity.beans.Store;

import com.myframework.smhj.hibernate.dao.BasicDao;

@Repository("shoppingCartDao")
public class ShoppingCartDaoImpl extends BasicDao<ShoppingCart> implements ShoppingCartDao {


	public ShoppingCartDaoImpl() {
		super(ShoppingCart.class);
		
	}

	@Override
	public Criteria getExample(ShoppingCart cart, String searchWord) {
		Criteria c = super.getExample(cart, searchWord);
		if (null != cart) {
			// 用户
			Member member = cart.getMember();
			if (null != member) {
				// 用户ID
				if (null != member.getMemberId()) {
					c.add(Restrictions.eq("member.memberId", member.getMemberId()));
				} else {
					// ...用户其它条件
				}				
			}
			// 店铺
			Store store = cart.getStore();
			if (null != store) {
				// 店铺ID
				if (null != store.getStoreId()) {
					c.add(Restrictions.eq("store.storeId", store.getStoreId()));
				} else {
					// ...店铺其它条件
				}
			}
			// ...购物车其它关联对象条件
		}
		// ...关键字searchWord查询条件
		return c;
	}
	
	@Override
	public void deleteEmptyByMemberId(Long memberId) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("memberId", memberId);
		executeUpdate("delEmptyByMemberIdHql", param);
		
	}


}
